package com.atguigu.factory.factorymethod.order;

import com.atguigu.factory.factorymethod.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author LYJ
 * @Description
 * @date 2021 年 09 月 10 日 上午10:19
 */
public abstract class OrderPizza {

    public abstract Pizza createPizza(String orderType);

    /**
     * 抽象方法是阔以有构造函数的
     */
    public OrderPizza() {
        Pizza pizza = null;
        String pizzaType;
        do {
            pizzaType = getType();
            pizza = createPizza(pizzaType);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }
        } while (true);
    }

    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
